package com.dosen.api.thought.core.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dosen.api.common.result.page.PageUtils;
import com.dosen.api.common.result.page.Query;
import com.dosen.api.thought.common.enums.ThoughtStorageMediaType;
import com.dosen.api.thought.core.service.dao.SearchThoughtDao;
import com.dosen.api.thought.core.service.entity.SearchThoughtEntity;
import com.dosen.api.thought.core.service.service.SearchThoughtService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("searchThoughtService")
public class SearchThoughtServiceImpl extends ServiceImpl<SearchThoughtDao, SearchThoughtEntity> implements SearchThoughtService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SearchThoughtEntity> page = this.page(
                new Query<SearchThoughtEntity>().getPage(params),
                new QueryWrapper<SearchThoughtEntity>()
        );
        List<SearchThoughtEntity> collect = page.getRecords().stream().filter(item -> {
            ThoughtStorageMediaType instance = ThoughtStorageMediaType.getInstance(item.getContentType());
            if (null != instance) {
                item.setContentTypeShow(String.format("%s(%s)", instance.getCnName(), instance.getEnName()));
            }
            return true;
        }).collect(Collectors.toList());
        page.setRecords(collect);
        return new PageUtils(page);
    }

}
